package com.booksystem.campuslibrarymanagementsystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.booksystem.campuslibrarymanagementsystem.commen.request.userquest.Personalrequest.Favorites;
import com.booksystem.campuslibrarymanagementsystem.commen.request.userquest.Personalrequest.Favoritesdvsd;
import com.booksystem.campuslibrarymanagementsystem.entity.BooksTable;
import com.booksystem.campuslibrarymanagementsystem.entity.FavoritesTable;
import com.booksystem.campuslibrarymanagementsystem.entity.FeedbacksTable;
import com.booksystem.campuslibrarymanagementsystem.mapper.FavoritesTableMapper;
import com.booksystem.campuslibrarymanagementsystem.service.FavoritesTableService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FavoritesTableServiceImpl extends ServiceImpl<FavoritesTableMapper, FavoritesTable>implements FavoritesTableService {
    @Autowired
    FavoritesTableMapper favoritesTableMapper;
    //添加收藏
    @Override
    public int saved(Favoritesdvsd ff){
        return favoritesTableMapper.saved(ff);
    }

    @Override
    public FavoritesTable existsByAccountAndBookid(String account, int bookid){
        return favoritesTableMapper.existsByAccountAndBookid(account,bookid);
    }

    @Override
    public List<FavoritesTable> selectfavoritesList(String title, String author, String category) {
        QueryWrapper<FavoritesTable> queryWrapper = new QueryWrapper<>();
        if (title != null && !title.isEmpty()) {
            // 对标题进行模糊查询，假设我们希望标题中包含输入的字符串
            queryWrapper.like("title", title);
        }
        if (author != null && !author.isEmpty()) {
            // 对作者进行模糊查询
            queryWrapper.like("author", author);
        }
        if (category != null && !category.isEmpty()) {
            queryWrapper.like("category", category); // 类别仍使用精确匹配
        }
        return favoritesTableMapper.selectList(queryWrapper);
    }
    @Override
    public List<FavoritesTable> selectByaccount(@Param("account") String account){
        return favoritesTableMapper.selectByaccount(account);
    }

    @Override
    public  int deleteByAccountAndBookid(@Param("account") String account, @Param("favoriteid") int favoriteid){
        return favoritesTableMapper.deleteByAccountAndBookid(account,favoriteid);
    }

}
